<?php
namespace app\admin\controller\v1;
use app\admin\Adminbase;

class GoodsLevel extends Adminbase 
{
	
	/**
	*添加等级分佣
	* /admin/v1/goods_level/add
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function add($cate_id,$data){
		$param = json_decode($data,true);
		$level = array_unique(array_column($param, 'level'));
		if(count($level) != count($param)){
			return $this->ReError("会员等级重复，请检查！");	
		}
		try {
			model('GoodsCateLevel')->where('cate_id',$cate_id)->delete();
			model('GoodsCateLevel')
				->allowField(['cate_id','level','discounts','commission_one','commission_two'])
				->saveAll($param);
			return $this->ReSucess();
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}

	
}



